package com.mk.dao.config;

import com.baomidou.mybatisplus.core.enums.SqlMethod;
import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.SqlSource;

/**
 * 根据ID强制物理删除 无视逻辑删除标记
 *
 * @author fuc
 * @since 2022/03/30
 */
public class HardDelete extends AbstractMethod {

    protected HardDelete(String methodName) {
        super(methodName);
    }

    @Override
    public MappedStatement injectMappedStatement(
            Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
        SqlMethod sqlMethod = SqlMethod.DELETE;
        String sql =
                String.format(
                        sqlMethod.getSql(),
                        tableInfo.getTableName(),
                        sqlWhereEntityWrapper(true, tableInfo),
                        sqlComment());
        SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
        return this.addDeleteMappedStatement(mapperClass, sqlSource);
    }
}
